mssql

推荐列表 站点导航

当前位置:首页 > 数据库 > mssql >

深入C++ string.find()函数的用法总结

来源:网络整理  作者:网络  发布时间:2020-12-13 08:48
本篇文章是对C++中string.find()函数的用法进行了详细的总结与分析,需要的朋友参考下...
position = s.find_first_of(flag);
cout<<"position "<<i<<" : "<<position<<endl;
string s = ”cdeabcigld“;

复制代码 代码如下:

复制代码 代码如下:

2.如果没有查询到,则返回string::npos,这是一个很大的数,其值不需要知道。
flag = "c";
else
cout<<"s.find(b,5) is : "<<position<<endl;
cout << "position is : " << position << endl;


string flag;

复制代码 代码如下:

1.如果string sub = ”abc“;
}
cout<<"s.rfind (flag) :"<<position<<endl;
s.find_first_of(sub), s.find_first_not_of(sub), s.find_last_of(sub), s.find_last_not_of(sub) 这四个函数,查找s中含有sub中任意字母的索引。
}
s.find(sub) , s.rfind(sub) 这两个函数,如果完全匹配,才返回匹配的索引,即:当s中含有abc三个连续的字母时,才返回当前索引。



position = s.find("jk");


using namespace std;
////find函数返回类型 size_type
flag="acb12389efgxyz789";
while((position=s.find_first_of(flag,position))!=string::npos)
position=s.rfind (flag);


i++;


{

复制代码 代码如下:

position=s.find("b",5);

cout << "s.find_first_of(flag) is : " << position << endl;
void main()
{
string s("1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8ha9i");
position++;
#include <iostream>
}
}

复制代码 代码如下:

//find 函数 返回jk 在s 中的下标位置


#include <string>
flag="3";
position=flag.find_first_not_of (s);

flag="a";
{

复制代码 代码如下:

int i=1;
//position=s.find_first_of(flag,position);
//从字符串s 下标5开始,查找字符串b ,返回b 在s 中的下标
//查找s 中flag 出现的所有位置。
//反向查找,flag 在s 中最后出现的位置
string::size_type position;
cout << "Not found the flag" + flag;

说明:
if (position != s.npos) //如果没找到,返回一个特别的标志c++中用npos表示,我这里npos取值是4294967295,

cout<<"flag.find_first_not_of (s) :"<<position<<endl;
position=0;
//查找flag 中与s 第一个不匹配的位置

{

//find 函数 返回flag 中任意字符 在s 中第一次出现的下标位置

相关热词: C++

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/sql/mssql/3237.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

深入C++ string.find()函数的用法总结

2020-12-13 编辑:网络

position = s.find_first_of(flag);
cout<<"position "<<i<<" : "<<position<<endl;
string s = ”cdeabcigld“;

复制代码 代码如下:

复制代码 代码如下:

2.如果没有查询到,则返回string::npos,这是一个很大的数,其值不需要知道。
flag = "c";
else
cout<<"s.find(b,5) is : "<<position<<endl;
cout << "position is : " << position << endl;


string flag;

复制代码 代码如下:

1.如果string sub = ”abc“;
}
cout<<"s.rfind (flag) :"<<position<<endl;
s.find_first_of(sub), s.find_first_not_of(sub), s.find_last_of(sub), s.find_last_not_of(sub) 这四个函数,查找s中含有sub中任意字母的索引。
}
s.find(sub) , s.rfind(sub) 这两个函数,如果完全匹配,才返回匹配的索引,即:当s中含有abc三个连续的字母时,才返回当前索引。



position = s.find("jk");


using namespace std;
////find函数返回类型 size_type
flag="acb12389efgxyz789";
while((position=s.find_first_of(flag,position))!=string::npos)
position=s.rfind (flag);


i++;


{

复制代码 代码如下:

position=s.find("b",5);

cout << "s.find_first_of(flag) is : " << position << endl;
void main()
{
string s("1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8ha9i");
position++;
#include <iostream>
}
}

复制代码 代码如下:

//find 函数 返回jk 在s 中的下标位置


#include <string>
flag="3";
position=flag.find_first_not_of (s);

flag="a";
{

复制代码 代码如下:

int i=1;
//position=s.find_first_of(flag,position);
//从字符串s 下标5开始,查找字符串b ,返回b 在s 中的下标
//查找s 中flag 出现的所有位置。
//反向查找,flag 在s 中最后出现的位置
string::size_type position;
cout << "Not found the flag" + flag;

说明:
if (position != s.npos) //如果没找到,返回一个特别的标志c++中用npos表示,我这里npos取值是4294967295,

cout<<"flag.find_first_not_of (s) :"<<position<<endl;
position=0;
//查找flag 中与s 第一个不匹配的位置

{

//find 函数 返回flag 中任意字符 在s 中第一次出现的下标位置

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/sql/mssql/3237.shtml

相关文章

风云图片

推荐阅读

返回mssql频道首页